package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsCategory;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class DtsCommentServiceImpl implements DtsCommentService {

    @Autowired
    DtsCommentMapper commentMapper;
    @Autowired
    StatMapper statMapper;

    @Override
    public IPage<DtsComment> queryPage(Integer page, Integer limit, String sort, String order, Integer userId, Integer valueId, List<Integer> list) {
        IPage<DtsComment> iPage = new Page<>(page,limit);

        QueryWrapper<DtsComment> qw = new QueryWrapper<>();
        if(!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)){
            if(order.equalsIgnoreCase("desc")){
                qw.orderByDesc(sort);
            }else {
                qw.orderByAsc(sort);
            }
        }

        if(userId != null){
            qw.like("c.user_id",userId);
        }
        if(valueId != null){
            qw.like("c.value_id",valueId);
        }

        if(list != null && list.size()>0){
            qw.in("g.brand_id",list);
        }

        iPage = statMapper.selectCommentPage(iPage,qw);
        return iPage;
    }

    @Override
    public void delete(DtsComment dtsComment) {
        dtsComment.setDeleted(true);
        commentMapper.updateById(dtsComment);
    }
}
